FS=8000;
X=0:1/FS:0.1;
sigma2=0.1;
sigma=sqrt(sigma2);

% 1
FS=8000;
sigma2=0.1;
RMSsin=1/sqrt(2); % RMS of a sine with amplitude 1
silence=zeros(1,800); % 8000 is 1s, 800 is 0.1s.
SNR=20*log10(RMSsin/sigma2); % signal-to-noise ratio
seq=[tone(1) silence tone(2) silence tone(3) silence tone(4) silence tone(5) silence tone(6) silence tone(7) silence tone(8) silence tone(9) silence tone(10) silence tone(11) silence tone(12)]; % create sequence of tones separated by silences.
seq=[tone(1) tone(4) tone(10)]; % create sequence of tones separated by silences.
%seqn=awgn(seq,SNR); % add white gaussian noise, with signal-to-noise ratio SNR.
%noise=randn(1,size(seq,2)).*sigma;
%seqn=seq+noise;
% wavplay(seq,FS);

% 2
t=tone(2);
tn=t+(randn(1,size(t,2)).*sigma);
f=fft(tn);
% plot(1:FS/size(f,2):FS,abs(f))
% multiply with LO for each frequency combined with LPF
% multiple BPF.

% key decoden kan met digitaal circuit, demux.

% 3
% 4.1
% F = [0.2170 0.2352 0.2352 0.2535];
% A = [0 1 0];
% % 10^(0.2/20)/10^(60/20) = 0.001
% DEV = [0.001 1 0.001];

% [N,Wn,BTA,FILTYPE] = kaiserord(F,A,DEV);
% B = fir1(N-100, Wn, FILTYPE, kaiser( N-100+1,BTA ),'noscale');
% freqz(B,1,1601,FS);figure(2);
% [n,fo,mo,w] = firpmord(F,A,DEV);
% b = firpm(n,fo,mo,w);
% freqz(b,1,1601,FS);

Wp = [0.2351 0.2353]; Ws = [0.2170 0.2535];
Rp = 0.2; Rs = 1;
% Cauer (elliptic) filter
[n,Wn] = ellipord(Wp,Ws,Rp,Rs);
[b,a] = ellip(n,Rp,Rs,Wn); % transfer function sum(b(i)/1+a(i))
freqz(b,a,1601,FS);

% n geeft 2 voor de orde, maar a en b hebben 2n+1 coefficienten.
% SNR?

% 
% c=fft(conv(f,B),1601);
% figure(2);
% plot(1:size(c,2),abs(c));
% figure(3);
% fb=freqz(B,1,1601,FS); % frequency response
% c=f.*fb';
% plot(1:size(c,2),abs(c));
% figure(4);
% freqz(B,1,1601,FS);